package cn.com.darly.videoandroidpm.common;

import android.content.Context;
import android.content.SharedPreferences;

import com.darly.common.ToastApp;

import cn.com.darly.videoandroidpm.BuildConfig;

/** 用户登录信息
 * @author Darly/张宇辉/2018/4/8 11:25
 * @version 1.0/cn.com.darly.videoandroidpm.common
 */
public class SystemLoginInfo {

    private static SharedPreferences mysp = null;
    private static final String PREFERENCE_NAME = "videoandroid";

    public static final String TOKEN = "usertoken";
    public static final String NAME = "name";
    public static final String ID = "id";
    public static final String ROLE = "role";
    public static final String LOGIN = "islogin";

    public static void init(Context context) {
        mysp = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
    }

    public static void setParamer(String key, String value){
        mysp.edit().putString(key, value).commit();
    }

    public static String getParamer(String key){
        return mysp.getString(key, "");
    }
    public static void setParamer(String key, boolean  value){
        mysp.edit().putBoolean(key, value).commit();
    }

    public static boolean getboolean(String key){
        return mysp.getBoolean(key, false);
    }


    public static void loginout(){
        mysp.edit().remove(TOKEN).commit();
        mysp.edit().remove(NAME ).commit();
        mysp.edit().remove(ROLE ).commit();
        mysp.edit().remove(LOGIN).commit();
    }


    /**
     * 设置请求接口的ip地址
     * @param str IP地址
     */
    public static void setServerIP(String str) {
        mysp.edit().putString("serverip", str).commit();
    }

    /**
     * 设置请求接口的端口号
     */
    public static void setServerPort( String str) {
        mysp.edit().putString("serverport", str).commit();
    }

    /**
     * 获取缓存中的请求接口IP地址
     */
    public static String getServerIP() {
        if (BuildConfig.DEBUG)
            return mysp.getString("serverip", "193.169.100.110");
        else
            return mysp.getString("serverip", "193.169.100.239");
    }

    /**
     * 获取请求的端口号
     */
    public static String getServerPort() {
        if (BuildConfig.DEBUG)
            return mysp.getString("serverport", "8081");
        else
            return mysp.getString("serverport", "6060");
    }



}
